import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import 'element-plus/theme-chalk/dark/css-vars.css'
import locale from 'element-plus/es/locale/lang/zh-cn'
import * as components from '@element-plus/icons-vue'

// svg图标
import 'virtual:svg-icons-register'

// 其他插件
import tab from './tab'
import * as auth from '../utils/auth'
import cache from './cache'
import * as modal from './modal'
import download from './download'

export default function installPlugins(app) {
  // element-plus图标全局注册
  for (const key in components) {
    const componentConfig = components[key]
    app.component(componentConfig.name, componentConfig)
  }

  // 使用element-plus 并且设置全局的大小
  app.use(ElementPlus, {
    locale: locale,
    // 支持 large、default、small
    size: cache.local().get('vv__element_size', 'default')
  })

  // 页签操作
  app.config.globalProperties.$tab = tab
  // 认证对象
  app.config.globalProperties.$auth = auth
  // 缓存对象
  app.config.globalProperties.$cache = cache
  // 模态框对象
  app.config.globalProperties.$modal = modal
  // 下载文件
  app.config.globalProperties.$download = download
}
